package com.wkbb.sports.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import com.wkbb.common.base.BaseServiceImpl;
import com.wkbb.common.constants.ErrorCode;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.common.dto.basic.StudentInfoDto;
import com.wkbb.common.dto.basic.UserDto;
import com.wkbb.common.enums.RoleTypeEnum;
import com.wkbb.common.handler.JsonUtil;
import com.wkbb.sports.dto.*;
import com.wkbb.sports.enums.SportsModelTypeEnum;
import com.wkbb.sports.enums.SportsUnitEnum;
import com.wkbb.sports.exception.MyException;
import com.wkbb.sports.exception.ResultEnum;
import com.wkbb.sports.feign.BasicFeignService;
import com.wkbb.sports.mapper.*;
import com.wkbb.sports.model.*;
import com.wkbb.sports.service.PracticeService;
import com.wkbb.sports.service.RuleService;
import com.wkbb.sports.service.StudentArenaService;
import com.wkbb.sports.utils.DateUtil;
import com.wkbb.sports.utils.SportsUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author lbh
 * @date 2021年03月29日 17:58:34
 * @description: 学生练习实现类
 */
@Service
@Slf4j
public class PracticeServiceImpl extends BaseServiceImpl<HlifeStudentPractice> implements PracticeService {

    @Autowired
    private HlifeStudentPracticeMapper hlifeStudentPracticeMapper;
    @Autowired
    private HlifeWorkMapper workMapper;
    @Autowired
    private HlifeWorkRuleMapper hlifeWorkRuleMapper;
    @Autowired
    private HlifeWorkStudentMapper hlifeWorkStudentMapper;
    @Autowired
    private HlifeWorkStudentHistoryMapper hlifeWorkStudentHistoryMapper;
    @Autowired
    private StudentArenaMapper studentArenaMapper;
    @Autowired
    private HlifeStudentPracticeProjectMapper hlifeStudentPracticeProjectMapper;
    @Autowired
    private HlifeUserMapper hlifeUserMapper;
    @Autowired
    private HlifeSportLevelMapper hlifeSportLevelMapper;
    @Autowired
    private BasicFeignService basicFeignService;
    @Autowired
    RuleService ruleService;
    @Autowired
    StudentArenaService arenaService;

    @Autowired
    public void setMapper(HlifeStudentPracticeMapper mapper) {
        super.setMapper(mapper);
    }

    @Override
    @Transactional(readOnly = true)
    public ResultDTO<StuSportStatisticsDto> getStuHomeSportStatistics(Long studentId, Byte projectKind) {
        String today = DateUtil.getDate();
        StuSportStatisticsDto data = hlifeStudentPracticeMapper.getStuHomeSportStatistics(studentId,projectKind,today);
        int aiCount = 123;
        if (data.getLevelSportCount() == null) data.setLevelSportCount(0);
        if (data.getStuSportLevel() == null) data.setStuSportLevel(0);
        data.setAiSportCount(aiCount + data.getLevelSportCount());
        return new ResultDTO<>(data);
    }

    @Override
    @Transactional(readOnly = true)
    public List<HlifeSportLevel> getSportLevelList(Map<String, Object> map) {
        HlifeSportLevelStu levelStu = hlifeSportLevelMapper.getSportLevelStu(map);
        int startLevel = 1;
        if (levelStu != null) {
            startLevel = levelStu.getLevel();
        }
        map.put("startLevel",startLevel);
        List<HlifeSportLevel> list = hlifeSportLevelMapper.getListByMapParams(map);
        for (HlifeSportLevel sportLevel : list){
            if (sportLevel.getState() != null && sportLevel.getState() == 1){
                startLevel+= 1;
                continue;
            }
            if (sportLevel.getLevel() == startLevel){
                sportLevel.setState(0);
            }else{
                sportLevel.setState(2);
            }
        }
        return hlifeSportLevelMapper.getListByMapParams(map);
    }

    @Override
    @Transactional(readOnly=true)
    public ResultDTO<List<StudentInfoDto>> getStudentInfoByFamily(Long id) {
        ResultDTO<List<StudentInfoDto>> resultDTO  = basicFeignService.getStudentInfoByFamily(id);
        if (resultDTO.isSuccess()){
            for (StudentInfoDto studentInfoDto: resultDTO.getData()){
                StuSportStatisticsDto statisticsDto = hlifeStudentPracticeMapper.getStuSportStatistics(studentInfoDto.getUserId(), (byte) 1,null);
                studentInfoDto.setDayNum(statisticsDto.getDayNum());
                studentInfoDto.setTotalTrainCount(statisticsDto.getTotalTrainCount() == null?0:statisticsDto.getTotalTrainCount());
                studentInfoDto.setTotalTrainTime(statisticsDto.getTotalTrainTime() == null?0:statisticsDto.getTotalTrainTime());
            }
        }
        return resultDTO;
    }

    @Override
    @Transactional(readOnly=true)
    public ResultDTO<LatelStuSportDto> getLatelyStuSport(Map<String, Object> params) {
        List<LatelStuSportDto> list = hlifeStudentPracticeMapper.getLatelyStuSport(params);
        LatelStuSportDto data;
//        log.info("getLatelyStuSport---list:{}", JsonUtil.stringify(list));
        if (!list.isEmpty() && list.get(0)!=null){
            data = list.get(0);
            params.put("sportDtos",true);
            List<LatelStuSportDto> sportDtos = hlifeStudentPracticeMapper.getLatelyStuSport(params);
            if (!sportDtos.isEmpty() && sportDtos.get(0)!=null){
                data.setSportDtos(sportDtos);
            }
        }else{
            data = new LatelStuSportDto();
            data.setTotalTrainCount(0);
            data.setTotalTrainTime(0);
            data.setAvgAMinuteCount(0);
            data.setFastAMinuteCount(0);
            data.setSportDtos(new ArrayList<>());
        }
        return ResultDTO.successResult(data);
    }

    @Override
    @Transactional(readOnly = true)
    public ResultDTO<StuSportStatisticsDto> getStuSportStatistics(Long studentId, Byte projectKind, String date) {
        StuSportStatisticsDto data = hlifeStudentPracticeMapper.getStuSportStatistics(studentId,projectKind,date);
        return new ResultDTO<>(data);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultDTO<HlifeStudentPractice> insertHlifeStudentPractice(HlifeStudentPractice hlifeStudentPractice, UserDto userDto) throws Exception  {
        if(hlifeStudentPractice.getStudentId() == null){
            throw new MyException(ResultEnum.STUDENT_ID_IS_NULL);
        }
        if(hlifeStudentPractice.getAchivement() == null){
            throw new MyException(ResultEnum.STUDENT_PRACTICE_ATTCAHMENT_IS_NULL);
        }
        if(hlifeStudentPractice.getActualTime() == null){
            throw new MyException(ResultEnum.STUDENT_PRACTICE_ACTUAL_TIME_IS_NULL);
        }
        ResultDTO<StudentInfoDto> res = basicFeignService.getStudentByStudentNo(null,null,hlifeStudentPractice.getStudentId(),null);
        if (res.isSuccess() && res.getData() != null){
            StudentInfoDto stu = res.getData();
            hlifeStudentPractice.setCreateBy(userDto.getName());
            hlifeStudentPractice.setUserNo(stu.getStudentNo());
            hlifeStudentPractice.setOrgId(stu.getOrgId());
            hlifeStudentPractice.setGradeId(stu.getGradeId());
            hlifeStudentPractice.setGradeName(stu.getGradeName());
            hlifeStudentPractice.setClassId(stu.getClassId());
            hlifeStudentPractice.setClassName(stu.getClassName());
            hlifeStudentPractice.setStudentName(stu.getName());
            hlifeStudentPractice.setHeadImgUrl(stu.getHeadImgUrl());
            hlifeStudentPractice.setUserType(stu.getUserType());
            hlifeStudentPractice.setProjectKind((byte) 1);
            hlifeStudentPractice.setSex(SportsUtils.getSexValue(stu.getSex()).byteValue());

            //限时1分钟模式下 计算评分
            if (hlifeStudentPractice.getTrainRequire() == 60){
//            if (hlifeStudentPractice.getModelType() == 1 && hlifeStudentPractice.getTrainRequire() == 60){
                //获取评分标准
                ScoreRuleDto scoreRuleDto = ruleService.queryScoreRule(stu.getGradeId(),hlifeStudentPractice.getProjectKind());
                calcStuScore(hlifeStudentPractice,scoreRuleDto);
            }

            Long workId = hlifeStudentPractice.getWorkId();
            Long arenaId = hlifeStudentPractice.getArenaId();
            Long levelId = hlifeStudentPractice.getLevelId();
            //参与擂台
            if (hlifeStudentPractice.getArenaId() != null){
                hlifeStudentPractice.setSportType(2);
                StudentArena studentArena = studentArenaMapper.getByPrimaryKey(arenaId);
                if (studentArena == null){
                    return ResultDTO.errorResult("错误!不存在的擂台");
                }
                if (studentArena.getState() == 0){
                    return ResultDTO.errorResult("错误!该擂台赛未开始");
                }
                if (studentArena.getState() == 2){
                    return ResultDTO.errorResult("错误!擂台赛已经结束");
                }
                int remainder = 1;
                Map<String, Object> params = new HashMap<>();
                params.put("arenaId",arenaId);
                params.put("studentId",hlifeStudentPractice.getStudentId());
                StudentArenaTeam team = null;
                if (studentArena.getType() == 1){
                    //数量限制。判断是否可以参赛
                    if (studentArena.getChallengeNum() > 0){
                        remainder = studentArena.getChallengeNum() - studentArenaMapper.getPlayerCount(params);
                    }
                    //个人赛，添加参赛选手
                    StudentArenaTeamStu arenaTeamStu = new StudentArenaTeamStu();
                    arenaTeamStu.setArenaId(arenaId);
                    arenaTeamStu.setStudentId(hlifeStudentPractice.getStudentId());
                    arenaTeamStu.setStudentName(stu.getName());
                    arenaTeamStu.setHeadImgUrl(stu.getHeadImgUrl());
                    arenaTeamStu.setUserType(stu.getUserType());
                    studentArenaMapper.insertTeamStu(arenaTeamStu);
                    if (remainder <= 0){
                        return ResultDTO.errorResult("该擂台赛已达最大报名限制");
                    }
                }else{
                    List<StudentArenaTeamStu> stuList = studentArenaMapper.findTeamStuList(params);
                    if (stuList.size() == 0){
                        //亲子赛
                        if (studentArena.getType() == 3){
                            Map<String, Object> params1 = new HashMap<>();
                            params1.put("arenaId",arenaId);
                            params1.put("userId",userDto.getId());
                            team = studentArenaMapper.findTeam(params1);
                            if (team == null){
                                return ResultDTO.errorResult("错误!未创建亲子擂台团队，无法参赛");
                            }else{
                                if (team.getChallengeNum() > 0){
                                    //战队
                                    int remainder1 = team.getChallengeNum() - team.getTeamNum();
                                    if (remainder1 <= 0){
                                        return ResultDTO.errorResult("错误!擂台团队已达最大人数限制");
                                    }
                                }
                                //自动加入团队
                                StudentArenaTeamStu teamStu = new StudentArenaTeamStu();
                                teamStu.setArenaId(arenaId);
                                teamStu.setArenaTeamId(team.getId());
                                teamStu.setStudentId(hlifeStudentPractice.getStudentId());
                                teamStu.setStudentName(hlifeStudentPractice.getStudentName());
                                teamStu.setHeadImgUrl(hlifeStudentPractice.getHeadImgUrl());
                                teamStu.setUserType(stu.getUserType());
                                studentArenaMapper.insertTeamStu(teamStu);
//                                studentArenaMapper.addTeamNum(team.getId());
                            }
                        }else {
                            return ResultDTO.errorResult("错误!未加入擂台团队，无法参赛");
                        }
                    }
                }
                if (studentArena.getChallengeCount() > 0){
                    remainder = studentArena.getChallengeCount() - studentArenaMapper.getPlayerChallengeCount(params);
                }
                if (remainder <= 0){
                    return ResultDTO.errorResult("该擂台赛已达最大挑战次数");
                }
                StudentArenaTrain train = new StudentArenaTrain();
                train.setAchievement(hlifeStudentPractice.getAchivement());
                BeanUtils.copyProperties(hlifeStudentPractice,train);
                train.setArenaId(arenaId);
                studentArenaMapper.insertTrain(train);
                //更新团队成绩
                if (studentArena.getType() != 1){
                    if (team == null){
                        team = studentArenaMapper.findTeam(params);
                    }
                    if (team == null){
                        return ResultDTO.errorResult("获取擂台团队失败");
                    }
                    params.put("arenaTeamId",team.getId());
                    StudentArenaTeam arenaTeam = studentArenaMapper.getTeamStatistical(params);
                    if (arenaTeam.getTotalAchievement() == null) arenaTeam.setTotalAchievement(0.0);
                    if (arenaTeam.getTotalTime() == null) arenaTeam.setTotalTime(0);
                    studentArenaMapper.updateTeam(arenaTeam);
                }
                arenaService.arenaChange(studentArena);
            }

            //有传作业ID的情况下，提交作业
            if (workId != null) {
                hlifeStudentPractice.setSportType(1);
                HlifeWorkStudentHistory hlifeWorkStudentHistory = new HlifeWorkStudentHistory();
                BeanUtils.copyProperties(hlifeStudentPractice,hlifeWorkStudentHistory);
                hlifeWorkStudentHistory.setWorkId(workId);
                hlifeWorkStudentHistory.setStatus(1);
                if (hlifeWorkStudentHistory.getModelType() == null) {
                    hlifeWorkStudentHistory.setModelType(4);//给默认值:4时间模式
                }
                hlifeWorkStudentHistory.setCreateBy(userDto.getName());
                HlifeWork hlifeWork = workMapper.getByPrimaryKey(workId);
                if (hlifeWork != null) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("studentId",hlifeStudentPractice.getStudentId());
                    params.put("workId",hlifeWork.getId());
                    HlifeWorkStudent workStudent = hlifeWorkStudentMapper.getByMapParams(params);
                    HlifeWorkRule hlifeWorkRule = hlifeWorkRuleMapper.getByPrimaryKey(hlifeWork.getRuleId());
                    if (hlifeWorkRule != null &&workStudent != null) {
                        boolean reached = false;

                        Integer actualTime = hlifeStudentPractice.getActualTime();
                        if (hlifeWorkRule.getUnit().equals(SportsUnitEnum.UNIT_MINUTE.getValue())){
                            actualTime = actualTime / 60;
                        }
                        Integer achivement = hlifeStudentPractice.getAchivement().intValue();
                        switch (hlifeWorkRule.getModelType()){
                            case 2: //限时限数
                                if (hlifeWorkRule.getSex() == 4) { //4区分男女
                                    if (hlifeStudentPractice.getSex() == 1) {
                                        reached = hlifeWorkRule.getBoyDuration() >= actualTime && hlifeWorkRule.getBoyNumber() <= achivement;
                                    } else {
                                        reached = hlifeWorkRule.getGirlDuration() >= actualTime && hlifeWorkRule.getGirlNumber() <= achivement;
                                    }
                                } else {
                                    reached = hlifeWorkRule.getDuration() >= actualTime && hlifeWorkRule.getNumber() <= achivement;
                                }
                                break;
                            case 3: //数量模式
                                //查询当天参与作业跳绳总次数
                                Map<String,Object>  map1  = new HashMap<>();
                                map1.put("workStudentId", workStudent.getId());
                                map1.put("today", DateUtil.getDate());
                                Integer todayTotalAchivement = hlifeWorkStudentHistoryMapper.getTodayTotalAchivement(map1);
                                if (todayTotalAchivement != null) achivement+= todayTotalAchivement;
                                if (hlifeWorkRule.getSex() == 4) { //4区分男女
                                    if (hlifeStudentPractice.getSex() == 1) {
                                        reached = hlifeWorkRule.getBoyNumber() <= achivement;
                                    } else {
                                        reached = hlifeWorkRule.getGirlNumber() <= achivement;
                                    }
                                } else {
                                    reached = hlifeWorkRule.getNumber() <= achivement;
                                }
                                break;
                            case 4: //时间模式
                                if (hlifeWorkRule.getSex() == 4) { //4区分男女
                                    if (hlifeStudentPractice.getSex() == 1) {
                                        reached = hlifeWorkRule.getBoyDuration() <= actualTime;
                                    } else {
                                        reached = hlifeWorkRule.getGirlDuration() <= actualTime;
                                    }
                                } else {
                                    reached = hlifeWorkRule.getDuration() <= actualTime;
                                }
                                break;
                        }
                        hlifeWorkStudentHistory.setReached(reached?1:0);
                        hlifeWorkStudentHistory.setWorkStudentId(workStudent.getId());
                        hlifeWorkStudentHistory.setProjectId(workStudent.getProjectId());
                        hlifeWorkStudentHistoryMapper.insert(hlifeWorkStudentHistory);

                        hlifeStudentPractice.setWorkStudentHistoryId(hlifeWorkStudentHistory.getId());

                        //查询学生本次作业提交历史中的最优成绩//只算已达标的
                        HlifeWorkStudentHistory hlifeWorkStudentHistoryOptimal = hlifeWorkStudentHistoryMapper.getHlifeWorkStudentHistoryOptimal(hlifeWorkStudentHistory.getWorkStudentId());
                        if (hlifeWorkStudentHistoryOptimal == null) {
                            //最好的成绩都未达标
                            hlifeWorkStudentHistoryOptimal = hlifeWorkStudentHistoryMapper.getHlifeWorkStudentHistoryOptimal1(hlifeWorkStudentHistory.getWorkStudentId());
                        }
                        HlifeWorkStudent hlifeWorkStudent = HlifeWorkStudent.generateHlifeWorkStudentFromHistoryDto(hlifeWorkStudentHistory, hlifeWorkStudentHistoryOptimal, userDto);
                        hlifeWorkStudentMapper.update(hlifeWorkStudent);
                    }
                }
            }
            HlifeSportLevel sportLevel = null;
            if (levelId != null) {
                sportLevel = hlifeSportLevelMapper.getByPrimaryKey(levelId);
                if (sportLevel == null){
                    return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
                }
                hlifeStudentPractice.setSportType(3);
            }
            if (hlifeStudentPractice.getJumpType() == null) hlifeStudentPractice.setJumpType(1);
            hlifeStudentPracticeMapper.insert(hlifeStudentPractice);
            //参与挑战
            if (sportLevel != null){
                HlifeSportLevelStu levelStu = new HlifeSportLevelStu();
                levelStu.setPracticeId(hlifeStudentPractice.getId());
                levelStu.setLevelId(levelId);
                int state = 1;
                if (sportLevel.getTargetNumber() != null){
                    //次数未达到要求
                    if (hlifeStudentPractice.getAchivement() < sportLevel.getTargetNumber()){
                        state = 2;
                    }
                }
                if (sportLevel.getTargetTime() != null){
                    //时间未达到要求
                    if (hlifeStudentPractice.getActualTime() > sportLevel.getTargetTime()){
                        state = 2;
                    }
                }
                levelStu.setState(state);
                levelStu.setStudentId(hlifeStudentPractice.getStudentId());
                hlifeStudentPractice.setState(state);
                hlifeSportLevelMapper.insertSportLevelStu(levelStu);
            }
            return new ResultDTO<>(hlifeStudentPractice);
        }
        return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
    }

    //计算评分
    public static void calcStuScore(HlifeStudentPractice stu, ScoreRuleDto scoreRuleDto){
        if (scoreRuleDto != null){
            double value = stu.getAchivement();
            if (scoreRuleDto.getPluses() != null){
                List<ScoreRulePlusDto> items = scoreRuleDto.getPluses().stream().filter(it -> it.getSex().equals(stu.getSex())).collect(Collectors.toList());
                for (ScoreRulePlusDto it: items){
                    if (value >= it.getMin() && value < it.getMax()) {
                        stu.setScoreLevel(1);
                        stu.setScore(scoreRuleDto.getScore());
                        stu.setPlusesScore(it.getScore());
                        return;
                    }
                }
            }
            if (scoreRuleDto.getItems() != null){
                List<ScoreRuleItemDto> items = scoreRuleDto.getItems().stream().filter(it -> it.getSex().equals(stu.getSex())).collect(Collectors.toList());
                for (ScoreRuleItemDto it: items){
                    if (value >= it.getMin() && value < it.getMax()) {
                        stu.setScoreLevel(it.getScoreLevel());
                        stu.setScore(it.getScore());
                        stu.setPlusesScore(0.0);
                        return;
                    }
                }
            }
        }else{
            stu.setScore(0.0);
            stu.setPlusesScore(0.0);
            stu.setScoreLevel(4);
        }
    }

    /**
     * 查询学生
     * */
    private HlifeUser getStudentInfo(long orgId, String studentNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("orgId", orgId);
        params.put("userType", (byte) RoleTypeEnum.STUDENT.getValue());
        params.put("userNo", studentNo);
        HlifeUser user = hlifeUserMapper.getByMapParams(params);
        if(user != null) {
            return user;
        }
        ResultDTO<StudentInfoDto> res = basicFeignService.getStudentByStudentNo(orgId,null,null, studentNo);
        if(res.isSuccess()) {
            StudentInfoDto dto = res.getData();
            if(dto != null) {
                HlifeUser hlifeUser = new HlifeUser();
                hlifeUser.setUserType((byte) RoleTypeEnum.STUDENT.getValue());
                hlifeUser.setOrgId(orgId);
                hlifeUser.setOrgName(dto.getOrgName());
                hlifeUser.setGradeId(dto.getGradeId());
                hlifeUser.setGradeName(dto.getGradeName());
                hlifeUser.setClassId(dto.getClassId());
                hlifeUser.setClassName(dto.getClassName());
                hlifeUser.setUserId(dto.getUserId());
                hlifeUser.setUserName(dto.getName());
                hlifeUser.setMobile(dto.getMobile());
                hlifeUser.setSex(SportsUtils.getSexValue(dto.getSex()).byteValue());
                hlifeUser.setHeadImg(dto.getHeadImgUrl());
                hlifeUser.setUserNo(studentNo);
                hlifeUserMapper.insert(hlifeUser);
                return hlifeUser;
            }
        }
        log.warn("====insertHlifeStudentPractice=======can not find student info by studentNo -> " + orgId + ", " + studentNo);
        return null;
    }

    /**
     *  某一个学生的练习列表或某一个练习详情
     * @param orgId
     * @param studentId
     * @return
     */
    @Override
    @Transactional(readOnly = true)
    public ResultDTO<PageInfo<HlifeStudentPractice>> getStudentPracticeListByStudentId(Integer orgId, Integer studentId, Integer practiceId,int pageNo,int pageSize){
        if(orgId == null){
            throw new MyException(ResultEnum.ORG_ID_IS_NULL);
        }
        if(studentId == null){
            throw new MyException(ResultEnum.STUDENT_ID_IS_NULL);
        }

        Page<Map<String,Object>> page = PageHelper.startPage(pageNo, pageSize);
        Map<String,Object> map=Maps.newHashMap();
        map.put("studentId",studentId);
        map.put("practiceId",practiceId);

        List<HlifeStudentPractice> hlifeStudentPracticeList=hlifeStudentPracticeMapper.getListByMapParams(map);
        PageInfo<HlifeStudentPractice> pageInfo = new PageInfo<HlifeStudentPractice>(hlifeStudentPracticeList);
        pageInfo.setTotal(page.getTotal());
        return new ResultDTO<>(pageInfo);
    }

    /**
     * 获取项目时长
     * @param studentId
     * @return
     */
    @Override
    public ResultDTO<HlifeStudentPracticeProject> getPracticeProject(String studentId,UserDto userDto){
        if(StringUtils.isEmpty(studentId)){
            throw new MyException(ResultEnum.STUDENT_ID_IS_NULL);
        }
        Map<String,Object> map=Maps.newHashMap();
        map.put("studentId",studentId);

        HlifeStudentPracticeProject hlifeStudentPracticeProject=hlifeStudentPracticeProjectMapper.getByMapParams(map);
        if(hlifeStudentPracticeProject == null){  //如果为空，则创建一个默认的【预留】
            hlifeStudentPracticeProject=new HlifeStudentPracticeProject();
            hlifeStudentPracticeProject.setDuration(60);
            hlifeStudentPracticeProject.setProjectName("跳绳");
            hlifeStudentPracticeProject.setProjectRuleId(1);
            hlifeStudentPracticeProject.setCreateBy(userDto.getName());
            hlifeStudentPracticeProject.setStudentId(Integer.parseInt(studentId));
            hlifeStudentPracticeProjectMapper.insert(hlifeStudentPracticeProject);
        }

        return new ResultDTO<>(hlifeStudentPracticeProject);
    }

}
